1 #region Using Statements
3 using System.Collections.Generic;
4 using Microsoft.Xna.Framework;
5 using Microsoft.Xna.Framework.Content;
6 using Microsoft.Xna.Framework.Graphics;
7 using Microsoft.Xna.Framework.Input;
8 using Microsoft.Xna.Framework.Storage;
9 using Microsoft.Xna.Framework.GamerServices;
10 using Microsoft.Xna.Framework.Media;
11 using Microsoft.Xna.Framework.Audio;
15 namespace SuperPolarity
18 /// This is the main type for your game
20 public class SuperPolarity : Game
22 public GraphicsDeviceManager graphics;
23 SpriteBatch spriteBatch;
25 public static int OutlierBounds;
31 protected Song TitleSong;
32 protected Song GameSong;
33 protected SoundEffect GameOverSound;
35 public SuperPolarity()
38 graphics = new GraphicsDeviceManager(this);
39 Components.Add(new GamerServicesComponent(this));
41 graphics.PreferMultiSampling = true;
42 graphics.PreferredBackBufferWidth = 1280;
43 graphics.PreferredBackBufferHeight = 720;
44 graphics.ToggleFullScreen();
46 Content.RootDirectory = "Content";
47 ActorFactory.SetGame(this);
48 ParticleEffectFactory.SetGame(this);
49 ActorManager.SetGame(this);
50 ScreenManager.SetGame(this);
52 EntryScreen = (Screen)new TitleScreen(this);
56 /// Allows the game to perform any initialization it needs to before starting to run.
57 /// This is where it can query for any required services and load any non-graphic
58 /// related content. Calling base.Initialize will enumerate through any components
59 /// and initialize them as well.
61 protected override void Initialize()
65 InputController.RegisterEventForKey("fullScreenToggle", Keys.F11);
66 InputController.Bind("fullScreenToggle", HandleFullScreenToggle);
68 EntryScreen.Initialize();
73 protected void HandleFullScreenToggle(float value)
75 graphics.ToggleFullScreen();
76 graphics.ApplyChanges();
80 /// LoadContent will be called once per game and is the place to load
81 /// all of your content.
83 protected override void LoadContent()
86 MediaPlayer.IsRepeating = true;
87 GameSong = Content.Load<Song>("Sound\\polaritytheme.wav");
88 GameOverSound = Content.Load<SoundEffect>("Sound\\gameover");
90 // Create a new SpriteBatch, which can be used to draw textures.
91 spriteBatch = new SpriteBatch(GraphicsDevice);
93 ScreenManager.Push(EntryScreen);
95 Player = new Player(this);
99 /// UnloadContent will be called once per game and is the place to unload
102 protected override void UnloadContent()
104 // TODO: Unload any non ContentManager content here
108 /// Allows the game to run logic such as updating the world,
109 /// checking for collisions, gathering input, and playing audio.
111 /// <param name="gameTime">Provides a snapshot of timing values.</param>
112 protected override void Update(GameTime gameTime)
114 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
117 ScreenManager.Update(gameTime);
121 base.Update(gameTime);
125 /// This is called when the game should draw itself.
127 /// <param name="gameTime">Provides a snapshot of timing values.</param>
128 protected override void Draw(GameTime gameTime)
130 GraphicsDevice.Clear(Color.White);
134 ScreenManager.Draw(spriteBatch);
141 public void PlaySong(string songName)
143 // temp stuff before media manager is in
144 if (songName == "game")
146 MediaPlayer.Play(GameSong);
150 public void GameOver()
152 var scoreScreen = new ScoreScreen(this);
153 scoreScreen.Initialize();
156 GameOverSound.Play();
158 ScreenManager.Push(scoreScreen);